<template>
  <div>
    <el-dialog :title="'详情页'" :close-on-click-modal="false" :visible.sync="visible" fullscreen center>
      <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
      <el-divider content-position="left">单据信息</el-divider>
      <el-form :model="dataForm" ref="dataForm" label-width="90px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="单据编号">
              <el-input v-model="dataForm.billId" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="入库类型">
              <el-input :v-model="dataForm.inveType" value="其他入库" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单据日期" prop="createTime">
              <el-input v-model="dataForm.createTime" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="制造商">
              <el-input v-model="dataForm.supplyName" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="收入仓位">
              <el-select size="mini" v-model="dataForm.inStockId" disabled>
                <el-option v-for="item in stockOptions" :value="item.id" :label="item.name" :key="item.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="制单人" prop="createUserName" disabled>
              <el-input v-model="dataForm.createUserName" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="memo">
              <el-input v-model="dataForm.memo" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <el-divider content-position="left">商品信息</el-divider>

      <div class="avue-crud">
        <el-table :data="dataList" border v-loading="dataListLoading" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="goodsCode" label="商品代码"></el-table-column>
          <el-table-column prop="goodsName" label="商品名称"></el-table-column>
          <el-table-column prop="spec" label="型号" width="80"></el-table-column>
          <el-table-column prop="unitType" label="计量单位" width="80" :formatter="unitTypeFormatter"></el-table-column>
          <el-table-column prop="auditTime" label="入库时间"></el-table-column>
          <el-table-column prop="goodsBarcode" label="商品条码"></el-table-column>
          <el-table-column prop="quantity" label="数量" width="60"></el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import {
    getInfoById,
    insertOtherPutStorage,
    editOtherPutStorageInfo
  } from "@/api/eims/purchase/other-warehouse"
  import { mapGetters } from "vuex"
  import {
    getStockList,
    getStockInfo
  } from "@/api/eims/stock"
  import {
    timeCompute,
    timeString
  } from "@/util/tools"
  import GoodsSearchSingle from '@/components/business/goods-search-single'
  import SearchSupply from '@/components/business/SearchSupply'
  import { getSupplyListByIds } from "@/api/eims/supply"

  export default {
    data() {
      return {
        dataListLoading: false,
        visible: false,
        dataForm: {
          id: 0,
          detailList: [],
          inStockId: "",
          inveType: 'OTI',
          memo: "",
          supplyName: '',
          supplyId: ''
        },
        stockOptions: [],
        supplyOptions: [],
        dataList: []
      };
    },
    created() {
      this.getStockListInfo()
    },
    computed: {
      ...mapGetters(["userInfo"])
    },
    components: {},
    methods: {
      init(id) {
        this.dataForm.id = id || 0;
        this.visible = true;
        this.$nextTick(() => {
          this.$refs["dataForm"].resetFields();
          if (this.dataForm.id) {
            getInfoById(this.dataForm.id).then(response => {
              if(response.data.code == '0'){
                this.dataForm = response.data.data
                this.dataList = response.data.data.detailList
                this.getSupplyList(this.dataForm.supplyId)
              }else{
                this.$message.error(response.data.msg)
              }
            })
          }
        });
      },
      handleSelectionChange(val) {
        this.selectionList = val;
      },
      //获取仓位
      getStockListInfo() {
        getStockList().then(response => {
          if(response.data.code == '0'){
            this.stockOptions = response.data.data
          }else{
            this.$message.error(response.data.msg)
          }
        })
      },
      unitTypeFormatter(row, column, cellValue, index) {
        switch (cellValue) {
          case '01':
            return '片'
            break;
          case '02':
            return '盒'
            break;
          case '03':
            return '副'
            break;
          case '04':
            return '瓶'
            break;
          case '05':
            return '张'
            break;
          case '06':
            return '把'
            break;
          case '07':
            return '个'
            break;
          case '08':
            return '只'
            break;
          case '09':
            return '套'
            break;
          case '10':
            return '天'
            break;
          case '11':
            return '包'
            break;
        }
      }
    }
  };
</script>
<style>
  .el-divider__text,
  .el-link {
    font-size: 18px;
  }
</style>
